﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendMsgToUser.aspx.cs" Inherits="WanWebApplication.Wechat.SendMsgToUser" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>发送消息到用户</title>
    <script src="../Content/lib/jquery/jquery-1.8.2.min.js"></script>
    <script>
        function setIndustry() {
            $.ajax({
                async: false,
                type: "POST",
                url: "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=<%= this.AccessToken  %>",
                data: {
                    "touser": "ofaHdt8LhL3jJv6pQWhIm9gpJEdU",
                    "template_id": "3SwfUqbchGZEjPgeIe0iMv9-KMDid40KVIREARZqKUI",
                    "url": "http://weixin.qq.com/download",
                    "data":
                    {
                        "a":
                        {
                            "value": "恭喜你购买成功！",
                            "color": "#173177"
                        }
                    }
                },
                dataType: "json",//接收类型
                contentType: "application/x-www-form-urlencoded", //请求类型
                success: function (data) {
                    alert(data)
                },
                error: function (err) {
                    alert("ajax错误：" + err.responseText);
                }
            });
        }
        function test(r) {
            alert(r)
        }
        function setIndustry1() {

            $.ajax({
                // async: false,
                type: "POST",
                url: "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=<%= this.AccessToken  %>",
                data: {
                    "touser": "ofaHdt8LhL3jJv6pQWhIm9gpJEdU",
                    "template_id": "3SwfUqbchGZEjPgeIe0iMv9-KMDid40KVIREARZqKUI",
                    "url": "http://weixin.qq.com/download",
                    "data":
                    {
                        "a":
                        {
                            "value": "恭喜你购买成功！",
                            "color": "#173177"
                        }
                    }
                },
                dataType: "jsonp",//接收类型
                jsonpCallback: "test"
            });
        }
        function setIndustry2() {
            $.ajax({
                async: false,
                type: "POST",
                url: "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=<%= this.AccessToken  %>",
                data: '{ "touser": "ofaHdt8LhL3jJv6pQWhIm9gpJEdU", "template_id": "3SwfUqbchGZEjPgeIe0iMv9-KMDid40KVIREARZqKUI", "url": "http://weixin.qq.com/download", "data": { "a": { "value": "恭喜你购买成功！", "color": "#173177" } } }',
                dataType: "jsonp",//接收类型
                jsonpCallback: "test"
            });
        }
        function test3() {
            $.post("https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=<%= this.AccessToken  %>", {
                "touser": "ofaHdt8LhL3jJv6pQWhIm9gpJEdU",
                "template_id": "3SwfUqbchGZEjPgeIe0iMv9-KMDid40KVIREARZqKUI",
                "url": "http://weixin.qq.com/download",
                "data":
                {
                    "a":
                    {
                        "value": "恭喜你购买成功！",
                        "color": "#173177"
                    }
                }
            }, function (a,b,c,d) {
                alert(a+b+c+d)
            },"json")
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <a href="javascript:setIndustry()">发送模版消息给用户
            </a>
            <br />
            <a href="javascript:setIndustry1()">发送模版消息给用户1
            </a>
            <br />
            <a href="javascript:setIndustry2()">发送模版消息给用户2
            </a>
            <br />
            <a href="javascript:test3()">发送模版消息给用户3
            </a>
            <br />
            <asp:Button ID="设置行业" runat="server" Text="设置行业" OnClick="设置行业_Click"   />
            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
            <br />
            <asp:Button ID="发消息" runat="server" Text="发消息" OnClick="Button1_Click" />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <asp:Button ID="得到模版" runat="server" Text="得到模版" OnClick="Button2_Click"  />
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        </div>
    </form>
</body>
</html>
